//
//  NewFeatureCell.swift
//  开心微博
//
//  Created by 郑开心 on 15/12/7.
//  Copyright © 2015年 郑开心. All rights reserved.
//

import UIKit

class NewFeatureCell: UICollectionViewCell {
    
    var image : UIImage!{
        didSet{
            setImage()
        }
    }
    
    lazy var shareButton : UIButton = {
        let shareButton = UIButton(type: UIButtonType.Custom)
        shareButton.setTitle("分享给大家", forState: UIControlState.Normal)
        shareButton.setImage(UIImage(named: "new_feature_share_true"), forState: UIControlState.Normal)
        shareButton.setImage(UIImage(named: "new_feature_share_false"), forState: UIControlState.Selected)
        shareButton.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        shareButton.sizeToFit()
        self.addSubview(shareButton)
        return shareButton
    }()
    
    
    lazy var startButton : UIButton = {
        let btn = UIButton(type: UIButtonType.Custom)
        btn.setTitle("开始微博", forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "new_feature_finish_button"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "new_feature_finish_button_highlighted"), forState: UIControlState.Selected)
        btn.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        btn.sizeToFit()
        btn.addTarget(self, action: "start", forControlEvents: UIControlEvents.TouchUpInside)
        self.contentView.addSubview(btn)
        return btn
    }()
    private lazy var imageView : UIImageView = {
        let imageView = UIImageView()
        self.contentView.addSubview(imageView)
        return imageView
    }()
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        // 分享按钮
        self.shareButton.center = CGPointMake(self.width * 0.5, self.height * 0.8);
        
        
        // 开始按钮
        self.startButton.center = CGPointMake(self.width * 0.5, self.height * 0.9);
        
        self.imageView.frame = self.bounds
        
    }
    
    func setIndexPath(indexPath: NSIndexPath,count: Int){
        if (indexPath.row == count - 1) { // 最后一页,显示分享和开始按钮
            self.shareButton.hidden = false
            self.startButton.hidden = false
            
            
        }else{ // 非最后一页，隐藏分享和开始按钮
            self.shareButton.hidden = true
            self.startButton.hidden = true
        }
        
    }
    
    func start(){
        shareButton.selected = !shareButton.selected
        let tabBarVc = KXTabBarController()
        UIApplication.sharedApplication().keyWindow?.rootViewController = tabBarVc
    }
    func setImage(){
        self.imageView.image = image
    }
}
